import React from 'react';
import {Button, ButtonProps} from "antd";

import { withModal, mountModal } from "vendor/components/pro-hoc/withModal";
import CreateOrEdit from './CreateOrEdit';
import {RespDataType} from "../../../api";

interface CreateOrEditBtnProps extends ButtonProps{
    deptId?: number;
    optType: "add" | "edit";
    fetchList: () => void;
    editData?: RespDataType.DeptItemInfo,
}

const CreateOrEditBtn:React.FC<CreateOrEditBtnProps> = ({deptId, optType, fetchList, editData, ...restProps}) => {

    return (
        <Button
            onClick={() => {
                const CreateOrEditModal = withModal(CreateOrEdit);
                mountModal(<CreateOrEditModal
                    modalProps={{
                        title: `${optType == "add" ? "添加" : "编辑"}组织`,
                        width: "50%",
                    }}
                    optType={optType}
                    deptId={deptId}
                    fetchList={fetchList}
                    editData={editData}
                />)
            }}
            {...restProps}
        />
    )
};

export default CreateOrEditBtn;